import { http } from "@/utils/http";

export interface VisitingAppointmentQuery extends BasePageQuery { // 列表查询参数
  status: string | number;
}

type VisitingAppointmentDTO = { // 返回数据
  id: string;
  userName: string;
};

export type VisitingAppointmentRequest = { // 添加修改请求参数
  id?: number;
};

/** 获取来访申请列表 */
export const getVisitingAppointmentListApi = (params?: VisitingAppointmentQuery) => {
  return http.request<ResponseData<PageDTO<VisitingAppointmentDTO>>>(
    "get",
    "/system/visit",
    {
      params
    }
  );
};

/** 添加来访申请 */
export const addVisitingAppointmentApi = (data: VisitingAppointmentRequest) => {
  return http.request<ResponseData<void>>("post", "/system/visit", {
    data
  });
};

/** 修改来访申请 */
export const updateVisitingAppointmentApi = (data: VisitingAppointmentRequest) => {
  return http.request<ResponseData<void>>(
    "put",
    `/system/visit/${data.id}`,
    {
      data
    }
  );
};

/** 审批来访申请 - 修改状态 */
export const checkVisitingAppointmentApi = (data: any) => {
  return http.request<ResponseData<void>>(
    "put",
    `/system/visit/checkVisit/${data.id}`,
    {
      data
    }
  );
};

/** 删除来访申请 */
export const deleteVisitingAppointmentApi = (data: Array<number>) => {
  return http.request<ResponseData<void>>("delete", "/system/visit", {
    params: {
      // 需要将数组转换为字符串  否则Axios会将参数变成 ids[0]:1  ids[1]:2 这种格式，后端接收参数不成功
      ids: data.toString()
    }
  });
};
